import {ServerlessRoutines} from '@remotion/serverless-client';
import {expect, test} from 'bun:test';
import {makeLambdaRenderMediaPayload} from '../make-lambda-payload';

test('Should include concurrency field in payload', async () => {
	const payload = await makeLambdaRenderMediaPayload({
		region: 'us-east-1',
		functionName: 'test-function',
		serveUrl: 'https://example.com',
		composition: 'test-composition',
		inputProps: {},
		codec: 'h264',
		imageFormat: 'jpeg',
		crf: undefined,
		envVariables: {},
		pixelFormat: undefined,
		proResProfile: undefined,
		x264Preset: null,
		privacy: 'public',
		jpegQuality: 80,
		maxRetries: 1,
		framesPerLambda: null,
		concurrency: 10,
		logLevel: 'info',
		frameRange: null,
		outName: null,
		timeoutInMilliseconds: 30000,
		chromiumOptions: {},
		scale: 1,
		everyNthFrame: 1,
		numberOfGifLoops: null,
		concurrencyPerLambda: 1,
		downloadBehavior: {type: 'play-in-browser'},
		muted: false,
		overwrite: false,
		audioBitrate: null,
		videoBitrate: null,
		encodingMaxRate: null,
		encodingBufferSize: null,
		webhook: null,
		forceHeight: null,
		forceWidth: null,
		rendererFunctionName: null,
		forceBucketName: null,
		audioCodec: null,
		colorSpace: null,
		deleteAfter: null,
		indent: false,
		forcePathStyle: false,
		metadata: null,
		apiKey: null,
		offthreadVideoCacheSizeInBytes: null,
		mediaCacheSizeInBytes: null,
		offthreadVideoThreads: null,
		storageClass: null,
		requestHandler: null,
		preferLossless: false,
	});

	expect(payload.type).toBe(ServerlessRoutines.start);
	expect(payload.concurrency).toBe(10);
});

test('Should handle null concurrency', async () => {
	const payload = await makeLambdaRenderMediaPayload({
		region: 'us-east-1',
		functionName: 'test-function',
		serveUrl: 'https://example.com',
		composition: 'test-composition',
		inputProps: {},
		codec: 'h264',
		imageFormat: 'jpeg',
		crf: undefined,
		envVariables: {},
		pixelFormat: undefined,
		proResProfile: undefined,
		x264Preset: null,
		privacy: 'public',
		jpegQuality: 80,
		maxRetries: 1,
		framesPerLambda: null,
		concurrency: null,
		logLevel: 'info',
		frameRange: null,
		outName: null,
		timeoutInMilliseconds: 30000,
		chromiumOptions: {},
		scale: 1,
		everyNthFrame: 1,
		numberOfGifLoops: null,
		concurrencyPerLambda: 1,
		downloadBehavior: {type: 'play-in-browser'},
		muted: false,
		overwrite: false,
		audioBitrate: null,
		videoBitrate: null,
		encodingMaxRate: null,
		encodingBufferSize: null,
		webhook: null,
		forceHeight: null,
		forceWidth: null,
		rendererFunctionName: null,
		forceBucketName: null,
		audioCodec: null,
		colorSpace: null,
		deleteAfter: null,
		indent: false,
		forcePathStyle: false,
		metadata: null,
		apiKey: null,
		offthreadVideoCacheSizeInBytes: null,
		mediaCacheSizeInBytes: null,
		offthreadVideoThreads: null,
		storageClass: null,
		requestHandler: null,
		preferLossless: false,
	});

	expect(payload.type).toBe(ServerlessRoutines.start);
	expect(payload.concurrency).toBe(null);
});
